package com.lb.service.impl;

import com.lb.entity.TbSalaTime;
import com.lb.dao.TbSalaTimeDao;
import com.lb.service.TbSalaTimeService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (TbSalaTime)表服务实现类
 *
 * @author libo
 * @since 2024-09-11 16:43:28
 */
@Service("tbSalaTimeService")
public class TbSalaTimeServiceImpl implements TbSalaTimeService {
    @Resource
    private TbSalaTimeDao tbSalaTimeDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TbSalaTime queryById(Integer id) {
        return this.tbSalaTimeDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param tbSalaTime 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<TbSalaTime> queryByPage(TbSalaTime tbSalaTime, PageRequest pageRequest) {
        long total = this.tbSalaTimeDao.count(tbSalaTime);
        return new PageImpl<>(this.tbSalaTimeDao.queryAllByLimit(tbSalaTime, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param tbSalaTime 实例对象
     * @return 实例对象
     */
    @Override
    public TbSalaTime insert(TbSalaTime tbSalaTime) {
        this.tbSalaTimeDao.insert(tbSalaTime);
        return tbSalaTime;
    }

    /**
     * 修改数据
     *
     * @param tbSalaTime 实例对象
     * @return 实例对象
     */
    @Override
    public TbSalaTime update(TbSalaTime tbSalaTime) {
        this.tbSalaTimeDao.update(tbSalaTime);
        return this.queryById(tbSalaTime.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.tbSalaTimeDao.deleteById(id) > 0;
    }
}
